package com.hoh.phonelocation.controller;

import com.hoh.phonelocation.common.BaseResponse;
import com.hoh.phonelocation.common.ResultUtils;
import com.hoh.phonelocation.exception.ErrorCode;
import com.hoh.phonelocation.exception.ThrowUtils;
import com.hoh.phonelocation.model.dto.GetLocationRequest;
import com.hoh.phonelocation.model.vo.PhoneLocationVO;
import com.hoh.phonelocation.service.PhoneInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.net.SocketTimeoutException;
import java.sql.SQLException;

/**
 * @Author hongzizhou
 * @Date 2025/3/2 下午2:47
 **/
@RestController
@CrossOrigin
@RequestMapping("/location")
public class PhoneInfoLocationController {

    @Resource
    private PhoneInfoService phoneInfoService;

    @PostMapping("/getLocation")
    public BaseResponse<PhoneLocationVO> getPhoneLocation(GetLocationRequest getLocationRequest) {
        ThrowUtils.throwIf(getLocationRequest.getPhone() == null, ErrorCode.PARAMS_ERROR, "请输入电话号码");

        PhoneLocationVO phoneLocation = phoneInfoService.getPhoneLocation(getLocationRequest.getPhone());

        return ResultUtils.success(phoneLocation);
    }

}
